package aroundadvice.around;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

//通知类  环绕通知类
public class MyAroundInterceptor implements MethodInterceptor {

    //执行的额外功能  参数：切到的目标对象 具体方法，方法的参数...
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {

        //额外功能
        System.out.println("===1===开启事务");
        //System.out.println("调用DAO "+name);  调用核心方法
        Object result = invocation.proceed();//放行环绕通知 执行目标方法

        System.out.println("放行方法返回的结果"+result);

        System.out.println("===3===关闭事务");

        //获取方法名
        String methodName = invocation.getMethod().getName();

        System.out.println("方法名: "+methodName);

        //获取方法的参数
        Object[] arguments = invocation.getArguments();

        for (int i = 0; i < arguments.length; i++) {
            Object argument = arguments[i];
            System.out.println("参数："+argument);
        }

        //获取目标类类名
        String className = invocation.getClass().getName();

        System.out.println("类名："+className);

        return result;
    }
}
